package com.boe.hbd.client.service.support;

import android.content.Context;

import com.boe.hbd.client.service.ImageLoaderService;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

public class ImageLoaderServiceSupport implements ImageLoaderService {

	private Context context = null;
	private ImageLoader imageLoader = null;

	public boolean isInitialized() {
		return context != null;
	}

	public void initialize(Context context) {
		if (this.context == null) {
			this.context = context;
			ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
					context.getApplicationContext())
					.threadPoolSize(3)
					.threadPriority(Thread.NORM_PRIORITY - 2)
					.memoryCacheSize(1500000)
					// 1.5 Mb
					.denyCacheImageMultipleSizesInMemory()
					.discCacheFileNameGenerator(new Md5FileNameGenerator())
					.enableLogging() // Not necessary in common
					.build();
			imageLoader = ImageLoader.getInstance();
			imageLoader.init(config);
		}
	}

	public void pause(Context context) {
	}

	public void resume(Context context) {
	}

	public void destroy(Context context) {
		if ( imageLoader != null) {
			imageLoader.stop();
		}
	}

	public ImageLoader getImageLoader() {
		return imageLoader;
	}
	
	

}
